package com.fzc.generic;

/**
 * Created with com.fzc.generic.
 * User: fzc
 * Date: 2017/9/26
 * Time: 23:10
 * Info:
 */
public class TestDemo {

    public static void main(String[] args) {
        Point<Integer> p = new Point<Integer>();
        p.setX(100);
        p.setY(200);
        System.out.println(p);

        Message<Integer> message = new Message<Integer>();
        message.setNode(123);
        fun(message);
    }

    //? 为通配符，可以接受任意类型， 泛型上限 ? extends   泛型下限  ? super String
    public static void fun(Message<? extends Number> message) {
        System.out.println(message.getNode());
    }
}

class Point<T> {
    private T x;
    private T y;

    public T getX() {
        return x;
    }

    public void setX(T x) {
        this.x = x;
    }

    public T getY() {
        return y;
    }

    public void setY(T y) {
        this.y = y;
    }

    @Override
    public String toString() {
        return "Point{" +
                "x=" + x +
                ", y=" + y +
                '}';
    }
}

class Message<T>{
    private T node;

    public T getNode() {
        return node;
    }

    public void setNode(T node) {
        this.node = node;
    }
}
